package com.action.blog.board;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.db.blogboard.*;
import com.opensymphony.xwork2.ActionContext;

public class ContentAction {

	private int jsptype;
	private int ono;
	private int no;
	private String content;
	private String page;
	private BoardVO vo = new BoardVO();
	private int rno;
	private List<BlogreplyVO> nblist = new ArrayList<BlogreplyVO>();
	private BoardDAO blogboard;

	public BoardDAO getBlogboard() {
		return blogboard;
	}

	public void setBlogboard(BoardDAO blogboard) {
		this.blogboard = blogboard;
	}

	public List<BlogreplyVO> getNblist() {
		return nblist;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getRno() {
		return rno;
	}

	public void setRno(int rno) {
		this.rno = rno;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public int getJsptype() {
		return jsptype;
	}

	public void setJsptype(int jsptype) {
		this.jsptype = jsptype;
	}

	public int getOno() {
		return ono;
	}

	public void setOno(int ono) {
		this.ono = ono;
	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}

	public BoardVO getVo() {
		return vo;
	}

	public void setVo(BoardVO vo) {
		this.vo = vo;
	}

	public String bbcontent() throws Exception {
		Map session = ActionContext.getContext().getSession();
		vo.setOno(ono);
		vo.setIdtype(session.get("idtype").toString());
		vo.setNo(no);
		vo = blogboard.boardSelectContentData(vo);

		nblist = blogboard.blogreplyAllData(no);

		System.out.println("content : " + no);
		blogboard.boardSelectIncrement(no);

		System.out.println(vo.toString());

		return "success";
	}

	public String bpcontent() throws Exception {
		Map session = ActionContext.getContext().getSession();
		vo.setOno(ono);
		vo.setIdtype(session.get("idtype").toString());
		vo.setNo(no);
		vo = blogboard.boardSelectContentData(vo);

		nblist = blogboard.blogreplyAllData(no);

		System.out.println("content : " + no);
		blogboard.boardSelectIncrement(no);

		System.out.println(vo.toString());

		return "success";
	}

	public String blogreply_insert() throws Exception {
		Map session = ActionContext.getContext().getSession();
		vo.setOno(ono);
		vo.setIdtype(session.get("idtype").toString());
		vo.setNo(no);
		vo = blogboard.boardSelectContentData(vo);

		BlogreplyVO rvo = new BlogreplyVO();
		rvo.setGroupno(no);
		rvo.setId(session.get("login").toString());
		rvo.setContent(content);

		blogboard.blogreplyInsert(rvo);

		nblist = blogboard.blogreplyAllData(no);

		blogboard.boardSelectIncrement(no);
		vo = blogboard.boardSelectContentData(vo);

		return replyContent();
	}

	public String blogreply_delete() throws Exception {
		Map session = ActionContext.getContext().getSession();
		vo.setOno(ono);
		vo.setIdtype(session.get("idtype").toString());
		vo.setNo(no);
		vo = blogboard.boardSelectContentData(vo);

		blogboard.blogreplyDelete(rno);

		nblist = blogboard.blogreplyAllData(no);

		vo = blogboard.boardSelectContentData(vo);

		return replyContent();
	}

	public String blogreply_update() throws Exception {
		Map session = ActionContext.getContext().getSession();
		vo.setOno(ono);
		vo.setIdtype(session.get("idtype").toString());
		vo.setNo(no);
		vo = blogboard.boardSelectContentData(vo);

		BlogreplyVO rvo = new BlogreplyVO();

		rvo.setContent(content);
		rvo.setNo(rno);
		System.out.println("1111111111111111111111111");
		blogboard.blogreplyUpdate(rvo);

		nblist = blogboard.blogreplyAllData(no);

		vo = blogboard.boardSelectContentData(vo);

		return replyContent();
	}

	public String replyContent() throws Exception {
		String result = "";
		if (jsptype == 1) {
			// list = BoardDAO.boardSelectData(vo);
			result = "BB";
		} else if (jsptype == 2) {
			result = "BP";
		}

		return result;
	}
}
